import Vue from 'vue'
import Vuex from 'vuex'
// import { resource } from '../api/resource/api.js';
import resource from './modules/Resource.js'
import notification from "./modules/Notification.js";

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        token: null,
        isLogin: false,
        user: {
            uid: "",
            username: "",
            email: "",
            avatar: "",
            isManager: false,
            applyStatus: 0,
        }
    },
    mutations: {
        setToken(token, newToken) {
            token = newToken;
        },
        setUser(state, data) {
            state.user = data
        },
        setisLogin(state, data) {
            state.isLogin = data
        },
        setAvatar(state, data) {
            state.user.avatar = data;
        },
        setApplyStatus(state, data) {
            state.user.applyStatus = data;
        }
    },
    getters: {
        isLogin: (state) => {
            return state.isLogin;
        },
        isManager: (state) => {
            return state.user.isManager;
        },
        getCurrUserAvatar: (state) => {
            return state.user.avatar;
        },
        getUserId: (state) => {
            return state.user.uid;
        },
        getUser: (state) => {
            return state.user;
        },
        getApplyStatus: (state) => {
            return state.user.applyStatus; //-1 0 1 2
        }
    },
    actions: {},
    modules: {
        message: notification,
        resource: resource,
    }
})